Skip to content

fix(kafka): respect structured content type when metadata headers are present - #339

Open
yumingjs wants to merge 1 commit into
cloudevents:mainfrom
yumingjs:fix/kafka-structured-mode
Open

yumingjs wants to merge 1 commit into
cloudevents:mainfrom
yumingjs:fix/kafka-structured-mode

Conversation

@yumingjs

@yumingjs yumingjs commented Dec 2, 2026

Copy link
Copy Markdown

Related Issue: Fixes #338

Type of change: Bug fix

Description

A structured Kafka event can also carry ce_ headers. Check the media type against the supplied event format before using those headers to infer binary mode. This keeps the envelope authoritative and preserves the existing fallback for other content types.

The regression cases cover a single metadata header, which caused a validation error, and all required headers, which caused the entire envelope to become the payload. They also cover mixed casing and a charset parameter. A binary message with application/json still uses its headers.

Verification

Both regression cases failed before the change. Afterward, all 356 core tests passed on Python 3.11.9. Ruff lint and formatting checks passed for both changed files.

Pre-submission checklist

  • Read the contribution guidelines.
  • Signed off the commit.
  • Added regression tests.
  • Updated the mode detection docstring.
  • Ran both pre-commit and tox.
  • Ready for review.

… present

Signed-off-by: Kong Liangyu <201232322+yumingjs@users.noreply.github.com>

@EmiRZx EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this covers the Kafka case I noted on #316. tested from_kafka with structured messages that also carry ce_ headers. a lone ce_subject no longer fails validation. with all required headers the envelope is read instead of becoming the data. mixed case, a charset parameter, a space before ; and a capitalized Content-Type name all stay structured. application/json and text/plain with headers still go binary. the new tests fail on main. it merges cleanly with #336. that one touches the same file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kafka decoder treats structured events with ce_ headers as binary

2 participants